﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Data;
using System.Collections;
using System.Text;

namespace Catering
{
    public partial class PostDate : System.Web.UI.Page
    {
        public static DataTable dtAVG = new DataTable();
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        #region 饮食管理
        [WebMethod]
        public static void BaoCunYingTingtest(string Update)
        {
            string str = Update;
        }
        #region 运算配餐人员平均年龄
        /// <summary>
        /// 运算配餐人员平均年龄 
        /// </summary>
        /// <param name="AVGold"></param>
        /// <returns></returns>
        [WebMethod]
        public static ArrayList AVG_Old(string AVGold)
        {
            #region 创建临时存储数据表
            ArrayList list = new ArrayList();

            dtAVG = new Catering_DataSet.dtAVGDataTable();
            #endregion

            #region 处理字符串
            string str = AVGold;
            string[] Groups = str.Split(new char[] { '|' });
            foreach (string strs in Groups)
            {
                if (strs.Length > 0)
                {
                    DataRow dr = dtAVG.NewRow();
                    string[] rows = strs.Split(new char[] { ',' });
                    dr["Sex"] = rows[0];
                    dr["Old"] = rows[1];
                    dr["Labor"] = rows[2];
                    dr["Renshu"] = rows[3];
                    dtAVG.Rows.Add(dr);
                }

            }
            #endregion


            #region 算出平均值
            Int32 Manold = 0;
            Int32 ManMunber = 0;
            Int32 Winole = 0;
            Int32 WinMunber = 0;

            foreach (DataRow dr in dtAVG.Rows)
            {
                if (dr["Sex"].ToString().Equals("1"))
                {
                    if (Convert.ToInt32(dr["Renshu"]) < 1)
                    {
                        ManMunber = 1;
                    }
                    //人数
                    ManMunber = ManMunber + Convert.ToInt32(dr["Renshu"]);
                    //年龄
                    if (Convert.ToInt32(dr["Old"]) < 1)
                    {
                        Manold = 1;
                    }
                    Manold = Manold + Convert.ToInt32(dr["Old"]) * 12 * Convert.ToInt32(dr["Renshu"]);

                }
                else
                {
                    if (Convert.ToInt32(dr["Renshu"]) < 1)
                    {
                        Winole = 1;
                    }
                    //人数
                    Winole = Winole + Convert.ToInt32(dr["Renshu"]);
                    if (Convert.ToInt32(dr["Old"]) < 1)
                    {
                        WinMunber = 1;
                    }
                    //年龄
                    WinMunber = WinMunber + Convert.ToInt32(dr["Old"]) * 12 * Convert.ToInt32(dr["Renshu"]);
                }
            }
            #endregion

            #region 将结果存储

            list.Add(ManMunber == 0 ? "" : ManMunber.ToString());
            list.Add((ManMunber == 0 ? "" : (Manold / ManMunber / 12).ToString()));
            list.Add(Winole == 0 ? "" : Winole.ToString());
            list.Add(Winole == 0 ? "" : (WinMunber / Winole / 12).ToString());

            #endregion
            #region 算推荐量
            foreach (DataRow drs in dtAVG.Rows)
            {
                new Catering.View_Operaction.Caipin_Manage_Operaction().GetNutrional(list, drs["Old"].ToString(), drs["Sex"].ToString(), drs["Labor"].ToString(), drs["Renshu"].ToString());
            }
            #endregion
            return list;

        }
        #endregion

        #region
        [WebMethod]
        public static void Library_Select(string Library)
        {
            string strLibrary = Library;
            Catering.Catering_Page.Caipin.Caipin_Manage.strLibrary = Library;
        }

        [WebMethod]
        public static string Raw_Del(string Raw_Del_Id)
        {
            return new Catering.View_Operaction.Caipin_Manage_Operaction().Del_Raw_Type(Raw_Del_Id) ? "OK" : "NO";
        }

        [WebMethod]
        public static string DelRawMaterialsInfoByID(string Raw_Del_Id)
        {
            return new Catering.View_Operaction.Caipin_Manage_Operaction().DelRawMaterialsInfoByID(Convert.ToInt32(Raw_Del_Id)) ? "OK" : "NO";
        }

        [WebMethod]
        public static string Dish_Del(string Dish_Del_Id)
        {
            return new Catering.View_Operaction.Caipin_Manage_Operaction().Del_Dish_Type(Dish_Del_Id) ? "OK" : "NO";

        }
        [WebMethod]
        public static string Raw_New(string Raw_New_Name)
        {
            try
            {
                new Catering.Catering_Page.Caipin.Caipin_jcsz.Leibieshezhi().butRawS_Click(Raw_New_Name);
                return "OK";
            }
            catch
            {
                return "NO";
            }
        }
        [WebMethod]
        public static string Raw_New_Min(string Dish_New_Name, string Type_Max_ID)
        {
            try
            {
                //new Catering.Catering_Page.Caipin.Caipin_jcsz.Leibieshezhi().butRaw_New_Min_Click(Dish_New_Name, Type_Max_ID);
                return "OK";
            }
            catch
            {
                return "NO";
            }
        }
        [WebMethod]
        public static string Dish_New(string Dish_New_Name)
        {
            try
            {
                new Catering.Catering_Page.Caipin.Caipin_jcsz.Leibieshezhi().butDishS_Click(Dish_New_Name);
                return "OK";
            }
            catch
            {
                return "NO";
            }
        }
        [WebMethod]
        public static ArrayList RawNutrient(string RawNumber)
        {
            ArrayList list = new ArrayList();

            list = new PostDate().setLableValue(RawNumber);
            return list;
        }
        [WebMethod]
        public static ArrayList Raw_Row_New(string RawName, string lblvalue)
        {
            Catering.View_Operaction_Common voc = new View_Operaction_Common();
            string str = voc.UIDataBing_RawMaterials();
            ArrayList list = new ArrayList();
            //ArrayList listvalue = new PostDate().setLableValue(0, RawName);
            //list =new PostDate().GetRawInfo( RawName);
            //foreach (object obj in listvalue)
            //{
            //    Int32 ints = Convert.ToInt32(obj.ToString());
            //    list.Add(ints);
            //}
            return list;
        }
        [WebMethod]
        public static ArrayList LoadTreeView(string strTreeView)
        {
            ArrayList list = new ArrayList();
            Catering.View_Operaction_Common voc = new View_Operaction_Common();

            string strTreeViews = voc.UIDataBing_RawMaterials();
            list.Add(strTreeViews);
            return list;
        }
        public ArrayList GetRawInfo(string RawName)
        {
            ArrayList list = new ArrayList();
            int i = 0;
            Catering_Rules.Species crs = new Catering_Rules.Species();
            Catering_Rules.T_RawMaterial crr = new Catering_Rules.T_RawMaterial();
            List<Catering_Model.E_RawMaterial> listModel = crr.GetModelList("RAWName='" + RawName + "'");
            Catering_Rules.NutrientComposition crnc = new Catering_Rules.NutrientComposition();
            foreach (Catering_Model.E_RawMaterial cmr in listModel)
            {
                //种属
                Catering_Model.Species cms = crs.GetModel(cmr.RAWZS);
                //热量
                Catering_Model.NutrientComposition cmnc = crnc.GetModelList("RawID=" + cmr.id)[0];
                //原料编号
                list.Add(cmr.id);
                //原料名称
                list.Add(cmr.RAWName);
                //原料种属 
                list.Add(cms.TypeName);
                //原料热量
                list.Add(cmnc.Content);
                Catering.View_Operaction.Caipin_Manage_Operaction cmo = new View_Operaction.Caipin_Manage_Operaction();
                string str = cmnc.Content;


                i = i + 1;
                if (Session["strTableHtml"] == null)
                {
                    Session["strTableHtml"] =
                        cmo.GetTableHtml(i, RawName, cms.TypeName, cmnc.Content);
                }
                else
                {
                    Session["strTableHtml"] = Session["strTableHtml"].ToString() +
                        cmo.GetTableHtml(i, RawName, cms.TypeName, cmnc.Content);
                }


                cmo.setDataToDataTable(Catering.Catering_Page.Caipin.Caipin_Manage.dt, i, RawName, cms.TypeName, cmnc.Content, cmr.id.ToString());
            }

            return list;

        }
        public ArrayList setLableValue(string RawNumber)
        {
            ArrayList list = new ArrayList();
            Catering_Rules.ViewOperaction crvo = new Catering_Rules.ViewOperaction();
            Catering.View_Operaction.Caipin_Manage_Operaction cmo = new View_Operaction.Caipin_Manage_Operaction();
            string[] inputvalue = RawNumber.Split(new char[] { ',' });
            int num = Convert.ToInt32(inputvalue[1]);


            DataTable dt = cmo.Nutrient_DataSetToDatatabl();
            if (dt != null && dt.Rows.Count > 0)
            {
                DataRow[] dr_Nutrient = dt.Select("RawName='" + inputvalue[0] + "'");
                if (inputvalue[3].Length > 0)
                {


                    if (Convert.ToInt32(inputvalue[1]) - 100 < 1)
                    {
                        num = 100 - num;
                        for (int i = 3; i < 27; i++)
                        {
                            list.Add(Convert.ToInt32(inputvalue[i]) - Convert.ToInt32(dr_Nutrient[0][i - 3]) * num);
                        }

                    }
                    else
                    {
                        num = num - 100;
                        for (int i = 3; i < 27; i++)
                        {
                            list.Add(Convert.ToInt32(inputvalue[i]) + Convert.ToInt32(dr_Nutrient[0][i - 3]) * num);
                        }

                    }
                }

            }

            return list;

        }
        public ArrayList setLableValue(Int32 RawNumber, string RawName)
        {
            ArrayList list = new ArrayList();
            Catering_Rules.ViewOperaction crvo = new Catering_Rules.ViewOperaction();
            Catering.View_Operaction.Caipin_Manage_Operaction cmo = new View_Operaction.Caipin_Manage_Operaction();

            DataTable dt = cmo.Nutrient_DataSetToDatatabl();
            if (dt != null && dt.Rows.Count > 0)
            {
                DataRow[] dr_Nutrient = dt.Select("RawName=" + RawNumber);
                if (dr_Nutrient[1] != null)
                {
                    for (int i = 1; i < 24; i++)
                    {
                        list.Add(Convert.ToInt32(dr_Nutrient[0][i]) * 100);
                    }

                }

            }

            return list;

        }

        public ArrayList setLableValue(string RawNumber, ArrayList list)
        {


            Catering.View_Operaction.Caipin_Manage_Operaction cmo = new View_Operaction.Caipin_Manage_Operaction();

            DataTable dt = cmo.Dish_DataSetToDatatabl(RawNumber);
            if (dt != null && dt.Rows.Count > 0)
            {

                for (int i = 1; i < dt.Columns.Count; i++)
                {
                    if (dt.Rows[0][i].ToString().Length > 0)
                    {
                        list.Add(Convert.ToInt32(dt.Rows[0][i]));
                    }
                }



            }
            return list;



        }
        [WebMethod]
        public static ArrayList Del_Dish_Info(string Dish_ID)
        {
            ArrayList list = new ArrayList();

            new Catering.View_Operaction.Caipin_Manage_Operaction().Del_Dish_Info(Dish_ID);
            return list;
        }
        [WebMethod]
        public static string Del_Raw_Info(string Raw_ID)
        {
            try
            {
                return new Catering.View_Operaction.Caipin_Manage_Operaction().Del_Raw_Info(Raw_ID) ? "OK" : "NO";
            }
            catch
            {
                return "NO";
            }
        }
        [WebMethod]
        public static ArrayList DishInfo_Operaction(string Del_DishInfo_ID)
        {
            ArrayList list = new ArrayList();
            new Catering.View_Operaction.Caipin_Manage_Operaction().Del_DishInfo_Operaction(Del_DishInfo_ID);
            return list;
        }
        #endregion

        #region 菜谱库
        [WebMethod]
        public static void Library_Select_Caipu(string Library)
        {
            string strLibrary = Library;
            Catering.Catering_Page.Caipin.Caipu_Manage.strLibrary = Library;
        }

        [WebMethod]
        public static ArrayList set_libery(string libery)
        {
            ArrayList list = new ArrayList();
            Catering_Rules.Group_tedian crl = new Catering_Rules.Group_tedian();
            DataSet ds = crl.GetAllList();
            if (ds != null && ds.Tables.Count > 0)
            {
                DataTable dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    list.Add(dr["PName"]);
                }

            }
            return list;
        }

        //[WebMethod]
        //public static ArrayList set_libery(string libery)
        //{
        //    ArrayList list = new ArrayList();
        //    Catering_Rules.Group_tedian crl = new Catering_Rules.Group_tedian();
        //    DataSet ds = crl.GetAllList();
        //    if (ds != null && ds.Tables.Count > 0)
        //    {
        //        DataTable dt = ds.Tables[0];
        //        foreach (DataRow dr in dt.Rows)
        //        {
        //            list.Add(dr["PName"]);
        //        }

        //    }
        //    return list;
        //}
        [WebMethod]
        public static string Set_Libery_Add(string Libery_string)
        {
            Catering.View_Operaction.Caipin_Manage_Operaction cmo = new View_Operaction.Caipin_Manage_Operaction();
            return cmo.AddLibery(Libery_string) ? "OK" : "NO";
        }
        [WebMethod]
        public static string Del_set_Libery(string Del_set_ID)
        {
            Catering_Rules.library crl = new Catering_Rules.library();
            return crl.Delete(Convert.ToInt32(Del_set_ID)) ? "OK" : "NO";
        }
        #endregion

        #region 采购计划
        [WebMethod]
        public static ArrayList CaitouEdit_Select(string GroupID, string ClassID, string StatTime, string StopTime)
        {
            ArrayList list = new ArrayList();
            Catering.View_Operaction.Caipin_Manage_Operaction cmo = new View_Operaction.Caipin_Manage_Operaction();
            string str = cmo.CaitouEdit_Select(GroupID, ClassID, StatTime, StopTime);
            list.Add(str);
            return list;
        }
        [WebMethod]
        public static ArrayList CaitouTemp_Select(string GroupID, string ClassID, string StatTime, string StopTime, string strNumber)
        {
            ArrayList list = new ArrayList();
            Catering.View_Operaction.Caipin_Manage_Operaction cmo = new View_Operaction.Caipin_Manage_Operaction();
            string str = cmo.CaitouTemp_Select(GroupID, ClassID, StatTime, StopTime, strNumber);
            list.Add(str);
            return list;
        }
        [WebMethod]
        public static string Purchase_Info_Del(string Select_Raw_ID)
        {
            Catering_Rules.PurchaseInfo crpi = new Catering_Rules.PurchaseInfo();
            Boolean blean = crpi.DeleteByWhere(" CID=" + Select_Raw_ID);
            if (blean)
            {
                blean = new Catering_Rules.Purchase().Delete(Convert.ToInt32(Select_Raw_ID));
            }
            return blean ? "OK" : "NO";
        }
        [WebMethod]
        public static string Del_RkglList(string Del_Id)
        {
            if (string.IsNullOrEmpty(Del_Id)) return "NO";
            Del_Id = Del_Id.TrimEnd();
            string[] splitid = Del_Id.Split(',');
            bool flag = false;
            if (splitid.Length > 0)
            {
                for (int j = 0; j < splitid.Length; j++)
                {
                    int id = 0;
                    Int32.TryParse(splitid[j], out id);
                    if (id > 0)
                    {
                        int result = new Catering_Rules.BalanceInfo().DelInDBInfo(id);
                        if (result == 3)
                        {
                            new Catering_Rules.InDbInfo().Delete(id);
                            flag = flag == false ? true : true;
                        }
                    }
                }
            }
            return flag == false ? "NO" : "OK";
        }

        [WebMethod]
        public static string Raw_Info_Del(string Select_Raw_ID)
        {

            Catering_Rules.PurchaseInfo crpi = new Catering_Rules.PurchaseInfo();
            Boolean blean = crpi.Delete(Convert.ToInt32(Select_Raw_ID));
            return blean ? "OK" : "NO";
        }

        [WebMethod]
        public static ArrayList Raw_Info_List(string Select_Raw_ID)
        {
            ArrayList list = new ArrayList();
            Catering_Rules.RAEInfo crr = new Catering_Rules.RAEInfo();
            Catering_Model.RAEInfo cmr = crr.GetModel(Convert.ToInt32(Select_Raw_ID));
            list.Add(cmr.RAWID);
            list.Add(cmr.Specifications);
            list.Add(cmr.CMP);
            return list;
        }
        [WebMethod]
        public static ArrayList Caigou_Info_Add_Row(string Add_Raw_Info, string CGID)
        {
            ArrayList list = new ArrayList();
            if (Add_Raw_Info != null && CGID.Length > 0)
            {
                list.Add(new PostDate().Insert_Row_Info_Caigou(Add_Raw_Info, CGID));
            }
            return list;

        }
        [WebMethod]
        public static void Caigou_Add_Row(string Add_Raw_Info, string CGID)
        {
            if (Add_Raw_Info != null && CGID.Length > 0)
            {
                new PostDate().Insert_Row_Caigou(Add_Raw_Info, CGID);
            }

        }
        /// <summary>
        /// 添加一行到数据库
        /// </summary>
        /// <param name="RowInfo"></param>
        /// <param name="CGID"></param>
        public void Insert_Row_Caigou(string RowInfo, string CGID)
        {
            StringBuilder sb = new StringBuilder();
            if (RowInfo != null)
            {
                string[] rowinfos = RowInfo.Split(new char[] { '|' });
                if (rowinfos.Length > 0)
                {
                    Catering_Rules.PurchaseInfo crpi = new Catering_Rules.PurchaseInfo();
                    foreach (string strrow in rowinfos)
                    {
                        if (strrow.Length > 0)
                        {
                            string[] row = strrow.Split(new char[] { ',' });
                            Catering_Model.PurchaseInfo cmpi = new Catering_Model.PurchaseInfo();
                            cmpi.id = crpi.GetMaxId();
                            cmpi.CID = Convert.ToInt32(CGID);
                            cmpi.DID = row[0].ToString();
                            cmpi.PName = new Catering_Rules.T_RawMaterial().GetModel(Convert.ToInt32(row[1].ToString())).RAWName;
                            cmpi.Specifications = row[2].ToString();
                            cmpi.Company = row[3].ToString();
                            cmpi.ProgramNumber = row[4].ToString();
                            cmpi.Requirement = row[5].ToString();
                            cmpi.Back = row[6].ToString();

                            int rawid = 0;
                            decimal sum = 0;
                            Int32.TryParse(cmpi.DID, out rawid);
                            decimal.TryParse(cmpi.ProgramNumber, out sum);
                            if (rawid > 0)
                            {
                                Catering_Model.E_RawMaterial rm = new Catering_Rules.T_RawMaterial().GetModel(rawid);
                                if (rm != null)
                                {
                                    string unit = new Catering_Rules.Units().GetModel(Convert.ToInt32(rm.temp2)).UName;
                                    bool iskg = true;
                                    decimal guige = 1;
                                    decimal UtilKg = Toolss.GetSpecifications(rm.id, unit, out iskg);
                                    guige = iskg ? 1000 : 1;
                                    decimal weight = Toolss.GetMathResult(UtilKg * sum, 2, 3);
                                    cmpi.temp1 = (weight * guige).ToString();
                                }
                            }
                            crpi.Add(cmpi);
                        }
                    }
                }
            }

        }
        public int Insert_Row_Info_Caigou(string RowInfo, string CGID)
        {
            StringBuilder sb = new StringBuilder();
            int i = 0;
            if (RowInfo != null)
            {
                string[] rowinfos = RowInfo.Split(new char[] { '|' });
                if (rowinfos.Length > 0)
                {
                    Catering_Rules.Purchase crpi = new Catering_Rules.Purchase();
                    foreach (string strrow in rowinfos)
                    {
                        if (strrow.Length > 0)
                        {
                            string[] row = strrow.Split(new char[] { ',' });
                            Catering_Model.Purchase cmpi = new Catering_Model.Purchase();
                            i = crpi.GetMaxId();
                            cmpi.id = i;
                            cmpi.FMID = Convert.ToInt32(CGID);
                            cmpi.PPName = row[0].ToString();
                            cmpi.Date = Convert.ToDateTime(row[1].ToString());
                            cmpi.EditDate = Convert.ToDateTime(row[2].ToString());
                            cmpi.BRid = 1;
                            cmpi.URid = 1;
                            cmpi.temp1 = row[5].ToString();
                            cmpi.Back = "";

                            crpi.Add(cmpi);
                        }
                    }
                }
            }
            return i;

        }
        #endregion

        #region 食谱


        [WebMethod]
        public static ArrayList CaiPin_Info_Tedian(string Dish_ID)
        {
            ArrayList list = new ArrayList();
            Catering_Rules.T_Dish crd = new Catering_Rules.T_Dish();
            Catering_Model.E_Dish md_Dish = crd.GetModel(Convert.ToInt32(Dish_ID));
            list.Add(md_Dish.Characteristic);
            list.Add(md_Dish.Name);
            return list;
        }
        #region 拖放
        [WebMethod]
        public static ArrayList shipu_tuo_fang(string Dish_ID, string strCanBie, string strDate)
        {
            ArrayList list = new ArrayList();
            View_Operaction_Common voc = new View_Operaction_Common();

            list.Add(voc.Getcai(Dish_ID, strCanBie, strDate));
            list.Add(voc.GetHanliang(Dish_ID, strCanBie, strDate));
            list = new PostDate().setLableValue(Dish_ID, list);
            string[] ids = strCanBie.Split(new char[] { ':' });
            if (ids.Length > 0)
            {
                list.Add(ids[1].Substring(2, 1));
            }
            new PostDate().Insert(Dish_ID, strCanBie, strDate);
            return list;
        }
        [WebMethod]
        public static string Del_shipu_tuo_fang(string Dish_ID)
        {

            //new PostDate().GetList(Dish_ID);

            return "OK";
        }
        private List<Catering_Model.E_RecipeInformation> GetList(string Dish_ID)
        {
            List<Catering_Model.E_RecipeInformation> list = null;
            if (Session["RecipeInformation"] != null)
            {
                string[] strid = Dish_ID.Split(new char[] { '|', ' ' });
                if (strid.Length > 0)
                {
                    if (strid[0] != null && strid[0].Length > 0)
                    {
                        string[] strids = strid[0].Replace("Dish", " ").Split(new char[] { ':', ' ' });
                        if (strids.Length > 0)
                        {
                            list = Session["RecipeInformation"] as List<Catering_Model.E_RecipeInformation>;
                            foreach (Catering_Model.E_RecipeInformation ri in list)
                            {
                                if (ri.Date.Equals(strids[1])
                                    && ri.CID == Convert.ToInt32(strids[2].Substring(strids[2].IndexOf("_") + 1))
                                    && ri.FMID == Convert.ToInt32(strids[2].Substring(0, 1)))
                                {
                                    list.Remove(ri);
                                }
                            }
                        }
                    }
                }

            }
            return list;
        }
        public Boolean Insert(string Dish_ID, string strCanBie, string strDate)
        {
            Boolean bl = false;

            List<Catering_Model.E_RecipeInformation> list = null;
            if (Session["RecipeInformation"] != null)
            {
                list = Session["RecipeInformation"] as List<Catering_Model.E_RecipeInformation>;
            }
            else
            {
                list = new List<Catering_Model.E_RecipeInformation>();
            }
            Catering_Rules.T_RecipeInformation crpi = new Catering_Rules.T_RecipeInformation();
            Catering_Model.E_RecipeInformation cmpi = new Catering_Model.E_RecipeInformation();
            string strc = strCanBie.Replace("Element", "");
            string[] strlist = strc.Split(new char[] { ':', ' ' });
            if (strlist.Length > 0)
            {

                cmpi.FMID = Convert.ToInt32(strlist[1].Substring(2));
                cmpi.Date = Convert.ToDateTime(strlist[0]);
                cmpi.CID = Convert.ToInt32(Dish_ID);
                cmpi.Week = Convert.ToInt32(strlist[1].Substring(0, 1));
                cmpi.AVGWeight = "1";
                cmpi.Price = 1;
                cmpi.Weight = "1";
                list.Add(cmpi);

                Session["RecipeInformation"] = list;

            }



            return bl;

        }
        #endregion
        [WebMethod]
        public static Boolean Del_set_shipu(string Del_shipu_ID)
        {
            Catering_Rules.T_Recipes crr = new Catering_Rules.T_Recipes();
            Catering_Rules.T_RecipeInformation crri = new Catering_Rules.T_RecipeInformation();
            Boolean bl = crri.DeleteList("MID=" + Del_shipu_ID);
            bl = crr.Delete(Convert.ToInt32(Del_shipu_ID));
            return bl;
        }

        #endregion

        #region
        [WebMethod]
        public static void shipulu_Add(string shipuku)
        {
            Catering_Rules.library crl = new Catering_Rules.library();

            if (shipuku.Length > 0)
            {
                string[] ku = shipuku.Split(new char[] { '|', ' ' });
                foreach (string strku in ku)
                {
                    if (strku.Length > 0)
                    {
                        string[] row = strku.Split(new char[] { ',', ' ' });
                        Catering_Model.library cml = new Catering_Model.library();
                        cml.id = crl.GetMaxId();
                        cml.LName = row[0];
                        cml.Back = row[2];
                        cml.temp1 = row[1];
                        cml.temp2 = "";
                        crl.Add(cml);
                    }
                }
            }
        }
        [WebMethod]
        public static void shipulu_Del(string shipuku)
        {
            Catering_Rules.library crl = new Catering_Rules.library();
            if (shipuku.Length > 0)
            {
                crl.Delete(Convert.ToInt32(shipuku));
            }

        }

        #endregion

        #region 基础设置
        [WebMethod]
        public static ArrayList Select_Max_Type(string strMaxtype)
        {
            ArrayList list = new ArrayList();
            list.Add(new View_Operaction.Caipin_Manage_Operaction().GetRawType(strMaxtype));
            return list;
        }

        #endregion
        #endregion

        #region 库房管理

        #region 入库管理

        [WebMethod]
        public static ArrayList rkgl_add(string strMaxtype, string but_Id, string row_id)
        {
            ArrayList list = new ArrayList();
            Catering.View_Operaction.DataBase_Manage_Operaction bmo = new View_Operaction.DataBase_Manage_Operaction();
            if (but_Id != null && row_id != null)
            {
                if (bmo.InputDataBase(strMaxtype))
                {
                    string str = bmo.InputDataBase(strMaxtype, row_id);
                    if (str.Length > 0)
                    {
                        list.Add(str);
                    }
                    else
                    {
                        list.Add("NO_Raw");
                    }
                }
                else
                {
                    list.Add("NO");
                }
                // list.Add(new View_Operaction.Caipin_Manage_Operaction().GetRawType(strMaxtype));
            }

            return list;
        }
        [WebMethod]
        public static string Raw_outpu_wring(string strMaxtype)
        {
            string strtemp1 = string.Empty;
            Catering.View_Operaction_Common voc = new View_Operaction_Common();
            if (strMaxtype != null && strMaxtype.Trim().Length > 0)
            {
                string[] strs = strMaxtype.Trim().Split(new char[] { ',', ' ' });
                Catering_Model.RoomWaing cmrw = voc.GetRaw_wring(strs[0], strs[1], strs[2], strs[3]);
                if (cmrw != null)
                {
                    strtemp1 = cmrw.MinContent.ToString();

                }
            }

            return strtemp1;
        }


        [WebMethod]
        public static ArrayList InputRoomInfo_Update(string strID)
        {
            ArrayList list = new ArrayList();
            Catering.View_Operaction.DataBase_Manage_Operaction bmo = new View_Operaction.DataBase_Manage_Operaction();
            if (strID != null && strID.Trim().Length > 0)
            {

                Catering_Model.FromRecords cmfr = new Catering_Rules.FromRecords().GetModel(Convert.ToInt32(strID == null ? "1" : strID));

                if (cmfr != null)
                {

                    list.Add(cmfr.RAWTID);
                    list.Add(cmfr.RAWIDs);
                    list.Add(cmfr.RAWID);
                    list.Add(cmfr.Numbers);
                    list.Add(cmfr.CMP);
                    list.Add(cmfr.Specifications);
                    list.Add(cmfr.Price);
                    list.Add(bmo.Getjiecun(cmfr.GroupID.ToString(), cmfr.ClassID.ToString(), cmfr.DBID.ToString(), cmfr.RAWID.ToString(), DateTime.Now));
                    list.Add(cmfr.OutDate.ToShortDateString());
                    list.Add(cmfr.AmountMoney);

                    list.Add(cmfr.Back);
                    Catering_Model.E_RawMaterial cmrr = new Catering_Rules.T_RawMaterial().GetModel(Convert.ToInt32(cmfr.RAWID));
                    if (cmrr != null)
                    {
                        list.Add(cmrr.InDBid);
                        list.Add(cmrr.RAWName);
                        //获取规格
                        DataTable dt_RMUnit = new Catering_Rules.RawMaterial_Unit().GetUnitByRawMaterialID(cmrr.id).Tables[0];
                        string strunit = "";
                        decimal tempjisuan = 1;
                        decimal tempjisuan1 = 1;
                        bool isstart = false;//是否开始计算
                        decimal danweinum = 1;//单位数量
                        Dictionary<string, decimal> danweiguige = new Dictionary<string, decimal>();
                        if (dt_RMUnit != null && dt_RMUnit.Rows.Count > 0)
                        {
                            for (int i = 0; i < dt_RMUnit.Rows.Count; i++)
                            {
                                decimal tempnum = Convert.ToDecimal(dt_RMUnit.Rows[i]["Number"]);
                                string danwei = dt_RMUnit.Rows[i]["UName"].ToString();

                                //从单位开始计算并记录单位规格数量
                                if (danwei == cmfr.CMP)
                                {
                                    isstart = true;
                                    danweinum = tempnum;
                                    if (danweiguige.Count > 0)
                                    {
                                        foreach (string oldunit in danweiguige.Keys)
                                        {
                                            strunit += "<option value='-" + (danweiguige[oldunit] * tempnum) + "'>" + oldunit + "</option>";
                                        }
                                    }

                                }
                                if (isstart)
                                {
                                    tempjisuan = tempjisuan * tempnum;
                                    strunit += "<option value='" + tempjisuan + "'>" + danwei + "</option>";
                                }
                                else//未开始计算
                                {
                                    tempjisuan1 = tempjisuan1 * tempnum;
                                    danweiguige.Add(danwei, tempjisuan1);
                                }
                            }
                            dt_RMUnit.Dispose();
                        }
                        list.Add(strunit);
                    }
                    else
                    {
                        list.Add("");
                        list.Add("");
                        list.Add("<option value='1'>" + cmfr.CMP + "</option>");
                    }
                }
            }
            //    list.Add(bmo.ShowOutputRoom(strID));
            return list;
        }

        [WebMethod]
        public static ArrayList rkgl_update(string strMaxtype)
        {
            ArrayList list = new ArrayList();
            Catering.View_Operaction.DataBase_Manage_Operaction bmo = new View_Operaction.DataBase_Manage_Operaction();
            list.Add(bmo.UpdateInputInfo(strMaxtype));

            return list;
        }

        [WebMethod]
        public static string Del_RkglListByDate(string Del_Date, string GroupID, string ClassID)
        {
            DateTime date = DateTime.MinValue;
            int group = 0;
            int delclass = 0;
            DateTime.TryParse(Del_Date, out date);
            Int32.TryParse(GroupID, out group);
            Int32.TryParse(ClassID, out delclass);
            if (date > DateTime.MinValue && group > 0 && delclass > 0)
            {
                string where = " GroupID=" + group + " AND ClassID=" + delclass + " AND year(IntDate)=" + date.Year + " AND Month(IntDate)=" + date.Month + " AND Day(IntDate)=" + date.Day + " ";
                DataTable dt = new Catering_Rules.InDbInfo().GetList(where).Tables[0];
                if (dt != null && dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        string indb_id = dt.Rows[i]["ID"].ToString();
                        int result = new Catering_Rules.BalanceInfo().DelInDBInfo(Convert.ToInt32(indb_id));
                        if (result == 3)
                        {
                            new Catering_Rules.InDbInfo().Delete(Convert.ToInt32(indb_id));
                        }
                    }
                    dt.Dispose();
                }
                return "OK";
            }
            return "NO";
        }

        [WebMethod]
        public static string rkgl_Del(string strID)
        {

            Catering.View_Operaction.DataBase_Manage_Operaction bmo = new View_Operaction.DataBase_Manage_Operaction();
            if (bmo.DelInputInfo(strID))
            {
                return "OK";
            }
            else
            {
                return "NO";
            }

        }

        #endregion

        #region 库房设置
        [WebMethod]
        public static string cangkushezhi_Del(string kufangshezhi)
        {

            Catering.View_Operaction.DataBase_Manage_Operaction bmo = new View_Operaction.DataBase_Manage_Operaction();
            if (kufangshezhi != null && kufangshezhi.Trim().Length > 0)
            {
                Int32 rowid = 0;
                Boolean bl = Int32.TryParse(kufangshezhi, out rowid);
                if (bl)
                {
                    if (new Catering_Rules.StorageRoom().Delete(rowid))
                    {
                        return "OK";
                    }
                    else
                    {
                        return "NO";
                    }

                }
                else
                {
                    return "NO";
                }
            }
            else
            {
                return "NO";
            }


        }
        [WebMethod]
        public static string cangkushezhi_Add(string rowinfo)
        {
            ArrayList list = new ArrayList();
            Catering.View_Operaction.DataBase_Manage_Operaction bmo = new View_Operaction.DataBase_Manage_Operaction();
            string strs = bmo.Save_cangkushezhi(rowinfo);
            if (strs != null && strs.Length > 0)
            {

                return "OK";
            }
            else
            {
                return "NO";
            }

        }
        #endregion

        #region 杂品申请
        [WebMethod]
        public static ArrayList Request_add(string strInfo)
        {
            ArrayList list = new ArrayList();
            Catering.View_Operaction.DataBase_Manage_Operaction bmo = new View_Operaction.DataBase_Manage_Operaction();
            list.Add(bmo.add_request_Info(strInfo));

            return list;
        }

        [WebMethod]
        public static string Request_stat(string strInfo)
        {

            return new View_Operaction.DataBase_Manage_Operaction().Update_request_Stat(strInfo);

        }
        #endregion

        #region 入库管理en

        [WebMethod]
        public static string Del_Excel_Out(string Del_Id)
        {
            string str = string.Empty;
            try
            {
                Catering.View_Operaction.DataBase_Manage_Operaction bmo = new View_Operaction.DataBase_Manage_Operaction();
                DataTable dt = new PostDate().GetDataInfo();
                if (dt != null && dt.Rows.Count > 0)
                {
                    bmo.Del_Excel_Out(Del_Id, dt);
                    new PostDate().SetDataInfo(dt);
                    str = "OK";
                }
                else
                {
                    str = "NO";
                }
                dt = new PostDate().GetImportinfo();
                if (dt != null && dt.Rows.Count > 0)
                {
                    bmo.Del_Excel_Out(Del_Id, dt);
                    new PostDate().SetImportinfo(dt);
                    str = "OK";
                }
                else
                {
                    str = "NO";
                }


            }
            catch
            {
                str = "NO";
            }
            return str;
        }
        private void SetDataInfo(DataTable dt)
        {
            Session["SescherInfo"] = dt;
        }
        private void SetImportinfo(DataTable dt)
        {
            Session["ExcelInfo"] = dt;
        }
        private DataTable GetDataInfo()
        {
            DataTable dt = new DataTable();
            if (Session["SescherInfo"] != null)
            {
                dt = Session["SescherInfo"] as DataTable;
            }
            return dt;
        }
        private DataTable GetImportinfo()
        {
            DataTable dt = new DataTable();
            if (Session["ExcelInfo"] != null)
            {
                dt = Session["ExcelInfo"] as DataTable;
            }
            return dt;
        }

        [WebMethod]
        public static ArrayList Add_null_Row(string Del_Id)
        {
            ArrayList list = new ArrayList();
            Catering.View_Operaction.DataBase_Manage_Operaction bmo = new View_Operaction.DataBase_Manage_Operaction();

            list.Add(bmo.ShowHtml(1));
            return list;
        }

        [WebMethod]
        public static string Input_DB_Manage(string InputInfo)
        {
            try
            {
                Catering.View_Operaction.DataBase_Manage_Operaction bmo = new View_Operaction.DataBase_Manage_Operaction();
                DataTable dts = bmo.Inset_Datatabl(new PostDate().GetDataInfo(), InputInfo);
                new PostDate().SetDataInfo(dts);
                return "OK";
            }
            catch
            {
                return "NO";
            }

        }
        #endregion

        #region 出库管理

        [WebMethod]
        public static string Del_CkglListByDate(string Del_Date, string GroupID, string ClassID)
        {
            DateTime date = DateTime.MinValue;
            int group = 0;
            int delclass = 0;
            DateTime.TryParse(Del_Date, out date);
            Int32.TryParse(GroupID, out group);
            Int32.TryParse(ClassID, out delclass);
            if (date > DateTime.MinValue && group > 0 && delclass > 0)
            {
                string where = " GroupID=" + group + " AND ClassID=" + delclass + " AND year(OutDate)=" + date.Year + " AND Month(OutDate)=" + date.Month + " AND Day(OutDate)=" + date.Day + " ";
                DataTable dt = new Catering_Rules.FromRecords().GetList(where).Tables[0];
                if (dt != null && dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        string strID = dt.Rows[i]["ID"].ToString();
                        int result = new Catering_Rules.BalanceInfo().DelFromRecords(Convert.ToInt32(strID));
                        if (result == 3)
                        {
                            new Catering_Rules.FromRecords().Delete(Convert.ToInt32(strID));
                        }
                    }
                    dt.Dispose();
                }
            }
            return "OK";
        }

        [WebMethod]
        public static string Del_CkglList(string Del_Id)
        {
            if (string.IsNullOrEmpty(Del_Id)) return "NO";
            Del_Id = Del_Id.TrimEnd();
            string[] splitid = Del_Id.Split(',');
            bool flag = false;
            if (splitid.Length > 0)
            {
                for (int j = 0; j < splitid.Length; j++)
                {
                    int id = 0;
                    Int32.TryParse(splitid[j], out id);
                    if (id > 0)
                    {
                        int result = new Catering_Rules.BalanceInfo().DelFromRecords(id);
                        if (result == 3)
                        {
                            new Catering_Rules.FromRecords().Delete(id);
                            flag = flag == false ? true : true;
                        }
                    }
                }
            }
            return flag == false ? "NO" : "OK";
        }

        #endregion

        [WebMethod]
        public static ArrayList InputRoomRawID_Chanage(string strID)
        {
            ArrayList list = new ArrayList();
            Catering.View_Operaction.DataBase_Manage_Operaction bmo = new View_Operaction.DataBase_Manage_Operaction();
            list = bmo.GetDataBaseNumber(strID);
            return list;
        }

        #endregion

        #region 日常管理
        [WebMethod]
        public static string Chengbaoshang_Add(string RowInfos)
        {
            if (new View_Operaction.Richang_Manage_Operaction().InsertInfoToServer(RowInfos))
            {
                return "OK";
            }
            else
            {
                return "NO";
            }
        }
        [WebMethod]
        public static string Chengbaoshang_Del(string RowInfos)
        {
            int id = 0;
            Boolean bl = Int32.TryParse(RowInfos == null ? "1" : RowInfos.Trim(), out id);
            if (bl)
            {
                bl = new Catering_Rules.ContractorInfo().DeleteList("CID=" + id);
                bl = new Catering_Rules.Contractor().Delete(id);
                //渤海湾1
            }
            if (bl)
            {
                return "OK";
            }
            else
            {
                return "NO";
            }
        }
        [WebMethod]
        public static string Chengbaoshang_Infos(string RowInfos)
        {
            return new View_Operaction.Richang_Manage_Operaction().show_Chengbaoshang_Info("CID=" + RowInfos);
        }
        [WebMethod]
        public static string Chengbaoshang_Infos_Del(string RowInfos)
        {
            int id = 0;
            Boolean bl = Int32.TryParse(RowInfos == null ? "1" : RowInfos.Trim(), out id);
            if (bl)
            {
                bl = new Catering_Rules.ContractorInfo().Delete(id);
            }
            if (bl)
            {
                return "OK";
            }
            else
            {
                return "NO";
            }
        }

        [WebMethod]
        public static ArrayList Chengbaoshang_Infos_Bind(string RowInfos)
        {
            int id = 0;
            ArrayList list = new ArrayList();
            Boolean bl = Int32.TryParse(RowInfos == null ? "1" : RowInfos.Trim(), out id);
            if (bl)
            {
                Catering_Model.ContractorInfo cmci = new Catering_Rules.ContractorInfo().GetModel(id);

                list.Add(cmci.CName);
                list.Add(cmci.GroupID);
                list.Add(cmci.CardNo);
                list.Add(cmci.JobCard);
                //list.Add(cmci.EffectiveArea);-------------------------------------------------------
                list.Add(cmci.Tel);
                //list.Add(cmci.temp1);--------------------------------------------
            }
            return list;
        }
        #region 详细信息

        [WebMethod]
        public static string Chengbaoshang_Infos_Add(string RowInfos, string rowid)
        {
            string infoid = string.Empty;
            new Catering.View_Operaction.Richang_Manage_Operaction().add_Chengbaoshang_Info(RowInfos, rowid, out infoid);
            return new Catering.View_Operaction.Richang_Manage_Operaction().show_Chengbaoshang_Info("id=" + infoid);

        }
        [WebMethod]
        public static string Chengbaoshang_Infos_Update(string RowInfos, string rowid)
        {
            return new Catering.View_Operaction.Richang_Manage_Operaction().Update_Chengbaoshang_Info(RowInfos, rowid);
        }
        #endregion
        #region  人员动态
        [WebMethod]
        public static ArrayList ruchangrenyuandognti_seacher(string ClassInfos, string stat, string stop)
        {

            ArrayList list = new ArrayList();

            if (ClassInfos != null && ClassInfos.Length > 0)
            {
                DataSet ds = new Catering_Rules.ClassInfo().GetList("CName='" + ClassInfos + "'");
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    DataTable dt = ds.Tables[0];
                    Catering_Model.OperationArea cmo = new Catering_Rules.OperationArea().GetModel(Convert.ToInt32(dt.Rows[0]["id"]));
                    string strShowHtml = new Catering.View_Operaction.Richang_Manage_Operaction().Seacher_Jiucan_List(cmo.id.ToString(), dt.Rows[0]["id"].ToString(), stat, stop);
                    Int32[] Numbers = new Catering.View_Operaction.Richang_Manage_Operaction().Seacher_renyuandongtai(cmo.id.ToString(), dt.Rows[0]["id"].ToString(), stat, stop);

                    list.Add(strShowHtml);
                    list.Add(Numbers[0]);
                    list.Add(Numbers[1]);
                    list.Add(Numbers[2]);
                    list.Add(Numbers[3]);
                    list.Add(Numbers[4]);

                }
            }
            return list;
        }
        #endregion
        #endregion

        #region 修改密码

        [WebMethod]
        public static int UserPass_Save_Add(string OldPass, string NewPass, string UserID)
        {
            int id = 0; Int32.TryParse(UserID, out id);
            if (id > 0)
            {
                Catering_Model.user md_old = new Catering_Rules.user().GetModel(id);
                if (md_old != null)
                {
                    if (md_old.UPWD == OldPass.Trim().GetMD5(""))
                    {
                        bool flag = new Catering_Rules.user().UpdateUserPass(NewPass.Trim().GetMD5(""), id);
                        if (flag) return 2; else return 1;
                    }
                    return 5;
                }
            }
            return 3;
        }

        #endregion

    }
}